﻿using System;

namespace Program05
{
    class Program
    {
        static void Main(string[] args)
        {
            //可以无限判断
            //性别
            string gender;
            //身高
            int height;
            //体重
            int weight;

            Console.WriteLine("请输入您的性别（男/女）:");
            //请用户输入性别
            gender = Console.ReadLine();

            //判定用户输入的性别是否合法
            while (!(gender == "女" || gender == "男"))
            {
                Console.WriteLine("您的输入性别不合法，请重新输入!");
                gender = Console.ReadLine();
            }

            //判定用户输入的身高
            Console.WriteLine("请输入您的身高：");
            while (!(int.TryParse(Console.ReadLine(), out height) && height > 56))
            {
                Console.WriteLine("您的输入身高不合法，请重新输入!");
            }

            //判断用户输入的体重

            Console.WriteLine("请输入您的体重：");
            while (!(int.TryParse(Console.ReadLine(), out weight) && weight > 20))
            {
                Console.WriteLine("您的输入体重不合法，请重新输入!");
            }

            //输入判断健康的结果信息
            string message = "";
            //调用方法判定健康状况
            message = DetectWeight(GetStandardWeight(gender, height, weight), weight);
            Console.WriteLine("您的健康状况是：" + message);
        }

        /// <summary>
        /// 计算标准体重
        /// </summary>
        /// <param name="gender">性别</param>
        /// <param name="height">身高</param>
        /// <param name="weight">体重</param>
        /// <returns></returns>
        public static int GetStandardWeight(string gender, int height, int weight)
        {
            int standardWeight;
            if (gender == "男")
            {
                //男士的标准体重
                standardWeight = (height - 80) * 7 / 10;
            }
            else
            {
                //女士的标准体重
                standardWeight = (height - 70) * 3 / 5;
            }
            return standardWeight;
        }

        /// <summary>
        /// 检查健康状况
        /// </summary>
        /// <param name="standardWeight">标准体重</param>
        /// <param name="weight">用户体重</param>
        /// <returns></returns>
        public static string DetectWeight(int standardWeight, int weight)
        {
            string message = "";
            if ((weight - standardWeight) > 0)
            {
                //体重正常,体重过重，肥胖
                if (weight < standardWeight * 11 / 10)
                    message = "体重正常";
                else
                {
                    if (weight > standardWeight * 11 / 10 && weight < standardWeight * 12 / 10)
                        message = "体重过重";
                    else
                        message = "肥胖";
                }
            }
            else
            {
                //体重正常,体重过轻，体重不足
                if (weight > standardWeight * 9 / 10)
                    message = "体重正常";
                else
                {
                    if (weight < standardWeight * 9 / 10 && weight > standardWeight * 8 / 10)
                        message = "体重过轻";
                    else
                        message = "体重不足";
                }
            }
            return message;
        }
    }
}
